/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package MobileArchitecture.impl;

import MobileArchitecture.Mobile;
import MobileArchitecture.MobileArchitecturePackage;
import MobileArchitecture.MobileEntity;
import MobileArchitecture.MobilePresentationModel;
import MobileArchitecture.MobileView;
import MobileArchitecture.MobileViewModel;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EcoreUtil;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Mobile Entity</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link MobileArchitecture.impl.MobileEntityImpl#getView <em>View</em>}</li>
 *   <li>{@link MobileArchitecture.impl.MobileEntityImpl#getViewModel <em>View Model</em>}</li>
 *   <li>{@link MobileArchitecture.impl.MobileEntityImpl#getPresentationModel <em>Presentation Model</em>}</li>
 *   <li>{@link MobileArchitecture.impl.MobileEntityImpl#getMobile <em>Mobile</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class MobileEntityImpl extends NamedElementImpl implements MobileEntity {
	/**
	 * The cached value of the '{@link #getView() <em>View</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getView()
	 * @generated
	 * @ordered
	 */
	protected MobileView view;

	/**
	 * The cached value of the '{@link #getViewModel() <em>View Model</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getViewModel()
	 * @generated
	 * @ordered
	 */
	protected MobileViewModel viewModel;

	/**
	 * The cached value of the '{@link #getPresentationModel() <em>Presentation Model</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPresentationModel()
	 * @generated
	 * @ordered
	 */
	protected MobilePresentationModel presentationModel;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected MobileEntityImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return MobileArchitecturePackage.Literals.MOBILE_ENTITY;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public MobileView getView() {
		return view;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetView(MobileView newView, NotificationChain msgs) {
		MobileView oldView = view;
		view = newView;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, MobileArchitecturePackage.MOBILE_ENTITY__VIEW, oldView, newView);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setView(MobileView newView) {
		if (newView != view) {
			NotificationChain msgs = null;
			if (view != null)
				msgs = ((InternalEObject)view).eInverseRemove(this, MobileArchitecturePackage.MOBILE_VIEW__ENTITY, MobileView.class, msgs);
			if (newView != null)
				msgs = ((InternalEObject)newView).eInverseAdd(this, MobileArchitecturePackage.MOBILE_VIEW__ENTITY, MobileView.class, msgs);
			msgs = basicSetView(newView, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, MobileArchitecturePackage.MOBILE_ENTITY__VIEW, newView, newView));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public MobileViewModel getViewModel() {
		return viewModel;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetViewModel(MobileViewModel newViewModel, NotificationChain msgs) {
		MobileViewModel oldViewModel = viewModel;
		viewModel = newViewModel;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, MobileArchitecturePackage.MOBILE_ENTITY__VIEW_MODEL, oldViewModel, newViewModel);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setViewModel(MobileViewModel newViewModel) {
		if (newViewModel != viewModel) {
			NotificationChain msgs = null;
			if (viewModel != null)
				msgs = ((InternalEObject)viewModel).eInverseRemove(this, MobileArchitecturePackage.MOBILE_VIEW_MODEL__ENTITY, MobileViewModel.class, msgs);
			if (newViewModel != null)
				msgs = ((InternalEObject)newViewModel).eInverseAdd(this, MobileArchitecturePackage.MOBILE_VIEW_MODEL__ENTITY, MobileViewModel.class, msgs);
			msgs = basicSetViewModel(newViewModel, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, MobileArchitecturePackage.MOBILE_ENTITY__VIEW_MODEL, newViewModel, newViewModel));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public MobilePresentationModel getPresentationModel() {
		return presentationModel;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetPresentationModel(MobilePresentationModel newPresentationModel, NotificationChain msgs) {
		MobilePresentationModel oldPresentationModel = presentationModel;
		presentationModel = newPresentationModel;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, MobileArchitecturePackage.MOBILE_ENTITY__PRESENTATION_MODEL, oldPresentationModel, newPresentationModel);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setPresentationModel(MobilePresentationModel newPresentationModel) {
		if (newPresentationModel != presentationModel) {
			NotificationChain msgs = null;
			if (presentationModel != null)
				msgs = ((InternalEObject)presentationModel).eInverseRemove(this, MobileArchitecturePackage.MOBILE_PRESENTATION_MODEL__ENTITY, MobilePresentationModel.class, msgs);
			if (newPresentationModel != null)
				msgs = ((InternalEObject)newPresentationModel).eInverseAdd(this, MobileArchitecturePackage.MOBILE_PRESENTATION_MODEL__ENTITY, MobilePresentationModel.class, msgs);
			msgs = basicSetPresentationModel(newPresentationModel, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, MobileArchitecturePackage.MOBILE_ENTITY__PRESENTATION_MODEL, newPresentationModel, newPresentationModel));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Mobile getMobile() {
		if (eContainerFeatureID() != MobileArchitecturePackage.MOBILE_ENTITY__MOBILE) return null;
		return (Mobile)eContainer();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetMobile(Mobile newMobile, NotificationChain msgs) {
		msgs = eBasicSetContainer((InternalEObject)newMobile, MobileArchitecturePackage.MOBILE_ENTITY__MOBILE, msgs);
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setMobile(Mobile newMobile) {
		if (newMobile != eInternalContainer() || (eContainerFeatureID() != MobileArchitecturePackage.MOBILE_ENTITY__MOBILE && newMobile != null)) {
			if (EcoreUtil.isAncestor(this, newMobile))
				throw new IllegalArgumentException("Recursive containment not allowed for " + toString());
			NotificationChain msgs = null;
			if (eInternalContainer() != null)
				msgs = eBasicRemoveFromContainer(msgs);
			if (newMobile != null)
				msgs = ((InternalEObject)newMobile).eInverseAdd(this, MobileArchitecturePackage.MOBILE__ENTITIES, Mobile.class, msgs);
			msgs = basicSetMobile(newMobile, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, MobileArchitecturePackage.MOBILE_ENTITY__MOBILE, newMobile, newMobile));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case MobileArchitecturePackage.MOBILE_ENTITY__VIEW:
				if (view != null)
					msgs = ((InternalEObject)view).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - MobileArchitecturePackage.MOBILE_ENTITY__VIEW, null, msgs);
				return basicSetView((MobileView)otherEnd, msgs);
			case MobileArchitecturePackage.MOBILE_ENTITY__VIEW_MODEL:
				if (viewModel != null)
					msgs = ((InternalEObject)viewModel).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - MobileArchitecturePackage.MOBILE_ENTITY__VIEW_MODEL, null, msgs);
				return basicSetViewModel((MobileViewModel)otherEnd, msgs);
			case MobileArchitecturePackage.MOBILE_ENTITY__PRESENTATION_MODEL:
				if (presentationModel != null)
					msgs = ((InternalEObject)presentationModel).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - MobileArchitecturePackage.MOBILE_ENTITY__PRESENTATION_MODEL, null, msgs);
				return basicSetPresentationModel((MobilePresentationModel)otherEnd, msgs);
			case MobileArchitecturePackage.MOBILE_ENTITY__MOBILE:
				if (eInternalContainer() != null)
					msgs = eBasicRemoveFromContainer(msgs);
				return basicSetMobile((Mobile)otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case MobileArchitecturePackage.MOBILE_ENTITY__VIEW:
				return basicSetView(null, msgs);
			case MobileArchitecturePackage.MOBILE_ENTITY__VIEW_MODEL:
				return basicSetViewModel(null, msgs);
			case MobileArchitecturePackage.MOBILE_ENTITY__PRESENTATION_MODEL:
				return basicSetPresentationModel(null, msgs);
			case MobileArchitecturePackage.MOBILE_ENTITY__MOBILE:
				return basicSetMobile(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs) {
		switch (eContainerFeatureID()) {
			case MobileArchitecturePackage.MOBILE_ENTITY__MOBILE:
				return eInternalContainer().eInverseRemove(this, MobileArchitecturePackage.MOBILE__ENTITIES, Mobile.class, msgs);
		}
		return super.eBasicRemoveFromContainerFeature(msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case MobileArchitecturePackage.MOBILE_ENTITY__VIEW:
				return getView();
			case MobileArchitecturePackage.MOBILE_ENTITY__VIEW_MODEL:
				return getViewModel();
			case MobileArchitecturePackage.MOBILE_ENTITY__PRESENTATION_MODEL:
				return getPresentationModel();
			case MobileArchitecturePackage.MOBILE_ENTITY__MOBILE:
				return getMobile();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case MobileArchitecturePackage.MOBILE_ENTITY__VIEW:
				setView((MobileView)newValue);
				return;
			case MobileArchitecturePackage.MOBILE_ENTITY__VIEW_MODEL:
				setViewModel((MobileViewModel)newValue);
				return;
			case MobileArchitecturePackage.MOBILE_ENTITY__PRESENTATION_MODEL:
				setPresentationModel((MobilePresentationModel)newValue);
				return;
			case MobileArchitecturePackage.MOBILE_ENTITY__MOBILE:
				setMobile((Mobile)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case MobileArchitecturePackage.MOBILE_ENTITY__VIEW:
				setView((MobileView)null);
				return;
			case MobileArchitecturePackage.MOBILE_ENTITY__VIEW_MODEL:
				setViewModel((MobileViewModel)null);
				return;
			case MobileArchitecturePackage.MOBILE_ENTITY__PRESENTATION_MODEL:
				setPresentationModel((MobilePresentationModel)null);
				return;
			case MobileArchitecturePackage.MOBILE_ENTITY__MOBILE:
				setMobile((Mobile)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case MobileArchitecturePackage.MOBILE_ENTITY__VIEW:
				return view != null;
			case MobileArchitecturePackage.MOBILE_ENTITY__VIEW_MODEL:
				return viewModel != null;
			case MobileArchitecturePackage.MOBILE_ENTITY__PRESENTATION_MODEL:
				return presentationModel != null;
			case MobileArchitecturePackage.MOBILE_ENTITY__MOBILE:
				return getMobile() != null;
		}
		return super.eIsSet(featureID);
	}

} //MobileEntityImpl
